package com.station.manage.controller;

import com.github.pagehelper.PageInfo;
import com.station.common.util.CommonResult;
import com.station.manage.model.Menu;
import com.station.manage.model.dto.AddMenuDto;
import com.station.manage.model.dto.UpdateMenuDto;
import com.station.manage.service.MenuService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 菜单控制
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单控制")
public class MenuController {


    @Autowired
    private MenuService menuService;

    @ApiOperation("添加菜单")
    @PostMapping("/add")
    public Object add(AddMenuDto addMenuDto){
        menuService.insert(addMenuDto);
        return CommonResult.success(null);
    }

    @ApiOperation("修改菜单")
    @PostMapping("/update")
    public Object update(UpdateMenuDto updateMenuDto){
        menuService.update(updateMenuDto);
        return CommonResult.success(null);
    }
    @ApiOperation("分页查询所有菜单")
    @GetMapping("/list")
    public Object findAll(int page , int limit){
        PageInfo<Menu> all = menuService.findAll(page, limit);
        return CommonResult.success(all);
    }
    @ApiOperation("根据目录名字查询菜单")
    @GetMapping("/findByParent")
    public Object findByParent(String pvalue){
        List<Menu> byParent = menuService.findByParent(pvalue);
        return CommonResult.success(byParent);
    }
    @ApiOperation("根据id查询菜单")
    @GetMapping("/findById")
    public Object findById(Long menuid ){
        Menu byId = menuService.findById(menuid);
        return CommonResult.success(byId);
    }
    @ApiOperation("查询所有目录")
    @GetMapping("/parent")
    public Object parent( ){
        List<Menu> parent = menuService.findParent();
        return CommonResult.success(parent);
    }

    @ApiOperation("查询未隐藏的目录和菜单，用于做功能显示")
    @GetMapping("/show")
    public Object show( ){
        List<Menu> show = menuService.findNotHide();
        return CommonResult.success(show);
    }
}
